import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
// 解决 vue-router 多次点击链接报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch((err) => err);
};
const routes = [ 
  {
    path: "/",
    name: "Index",
    redirect: "/index",
    component: () => import("@/views/index/index.vue"),
    children: [
      {
        path: "/index",
        name: "main",
        component: () => import("@/views/main/main.vue"),
      },
      {
        path: "/user",
        name: "user",
        redirect: "/user/list",
        component: () =>
          import(/* webpackChunkName: "navigator" */ "@/views/main"),
        children: [
          {
            path: "list",
            name: "list",
            meta: {
              title: "列表",
              icon: "",
            },
            component: () =>
              import(
                /* webpackChunkName: "navigator" */ "@/views/user/list"
              ),
          },
          {
            path: "add",
            name: "add",
            meta: {
              title: "新建",
              icon: "",
            },
            component: () =>
              import(/* webpackChunkName: "navigator" */ "@/views/user/add"),
          },
          {
            path: "edit",
            name: "edit",
            meta: {
              title: "编辑",
              icon: "",
            },
            component: () =>
              import(/* webpackChunkName: "navigator" */ "@/views/user/edit"),
          },
        ],
      },
      {
        path: "/test",
        name: "test",
        redirect: "/test/table",
        component: () =>
          import(/* webpackChunkName: "navigator" */ "@/views/main"),
        children: [
          {
            path: "table",
            name: "table",
            meta: {
              title: "表格演示",
              icon: "",
            },
            component: () =>
              import(/* webpackChunkName: "navigator" */ "@/views/test/table"),
          },
          {
            path: "form",
            name: "form",
            meta: {
              title: "表单演示",
              icon: "",
            },
            component: () =>
              import(/* webpackChunkName: "navigator" */ "@/views/test/form"),
          },
          {
            path: "tmp",
            name: "tmp",
            meta: {
              title: "模板",
              icon: "",
            },
            component: () =>
              import(/* webpackChunkName: "navigator" */ "@/views/test/tmp"),
          }
        ]
      }
    ],
  }, 
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/Login.vue"),
  }
];

const router = new VueRouter({
  routes,
});

export default router;
